info = require'jelly/info'
util = require'jelly/util'
import before_cursor, after_cursor from util
import tbl_contains from vim

two_char_prefixes = {'Ø', 'Æ', 'æ', 'Œ', 'œ', 'Ð'}

help = ->
  before = before_cursor!
  after = after_cursor!
  before_len = before\ulen!
  after_len = after\ulen!
  if after_len == 0
    print 'The cursor needs to be on a character'
    return
  command = after\uindex(1)
  if before_len != 0
    prev_char = before\uindex(before_len)
    if tbl_contains(two_char_prefixes, prev_char)
      command = prev_char..command
  if tbl_contains(two_char_prefixes, command) and after_len != 1
    command ..= after\uindex(2)
  print command
  print if info[command]
    info[command].description
  else
    'Information not found'

{ :help }
